package br.com.ecommerce.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import br.com.suricattus.surispring.framework.domain.BaseEntity;

/**
 * @author marco.nascimento
 */
@MappedSuperclass
public abstract class SimpleEntitySupport<PK extends Number> extends BaseEntity {
	
    private static final long serialVersionUID = 1L;

    @Version
    @Column(name = "versao", nullable = false)
    protected Integer versao;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dataCriacao", nullable = false)
    protected Date dataCriacao;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dataAtualizacao", nullable = false)
    protected Date dataAtualizacao;

    @PrePersist
    protected void insertTrigger() {
        this.dataCriacao = new Date();
        this.dataAtualizacao = new Date();
    }
    
    @PreUpdate
    protected void updateTrigger() {
        this.dataAtualizacao = new Date();
    }
}